package com.pat.common.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import com.aliyun.oss.OSSClient;

public class OssUtil {

	
	public static final String BUCKET = "petstan";
	public static final String PRFIX = "img/";
	public static final String PIC_DEFAULT_TYPE = ".png";
	public static final String OSS_PREFIX = "oss-cn-shanghai.aliyuncs.com";
	private static OSSClient ossClient = new OSSClient(OSS_PREFIX, "LTAIFtXO9lY3sWiS", "hoa7wwN8vodjf46mCcD2gbRPmKy2aD");
	
	public static String uploadPIC(String name,InputStream is){
		try{
			String key = PRFIX+name+PIC_DEFAULT_TYPE;
			ossClient.putObject("petstan", key, is);
			return "http://"+BUCKET+"."+OSS_PREFIX+"/"+key;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				is.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return null;
	}
	
	public static void main(String[] args) throws FileNotFoundException {
		FileInputStream fis = new FileInputStream("C:\\Users\\Administrator\\Desktop\\h5\\b_index_h5\\images\\banner.png");
		String s = uploadPIC("abc",fis);
		System.out.println(s);
	}
}
